package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;

import static tests.LoginPage.url;

public class ListPage extends Utils {
    public static String url = "http://8.137.19.140:9090/blog_list.html";
    public ListPage() {
        super(url);
    }
    //检查博客页表列
    //检查个人信息、博客列表、菜单模块
    public void checkBlogList() throws IOException {
        //检查博客列列表页面是否可见
        driver.findElement(By.cssSelector("body"));
        //检查个人信息的头像
      driver.findElement(By.cssSelector("body > div.container > div.left > div > img"));
      //检查个人的昵称
        driver.findElement(By.cssSelector("body > div.container > div.left > div > h3"));
        //检查个人的github
        driver.findElement(By.cssSelector("body > div.container > div.left > div > a"));
        //检查个人文章字段是否可见
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)"));
        //检查个人文章数量是否可见
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)"));
        //检查分类字段是否可见
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)"));
        //检查分类数量是否可见
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(2)"));


        //检查博客列表的标题是否可见
        driver.findElement(By.cssSelector("body > div.container > div.right > div > div.title"));
        //检查博客列表的日期是否可见
        driver.findElement(By.cssSelector("body > div.container > div.right > div > div.date"));
        //检查查看博客全文按钮是否可见
        driver.findElement(By.cssSelector("body > div.container > div.right > div > a"));
    }
    //检查博客按钮功能，以及按钮跳转的页面是否正确后可查看吗？
    public void checkBlogButton() throws IOException {
//        //点击查看写博客按钮，跳转到写博客页面
//        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();
//        //回退到博客列表页
//        driver.navigate().back();
        //博客列表跳转前页标题
        String pre_title = driver.findElement(By.cssSelector("body > div.container > div.right > div > div.title")).getText();
        //点击查看全文按钮，跳转到博客详情页
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a")).click();
        //获取详情页标题
        String jump_title = driver.findElement(By.cssSelector("body > div.container > div.right > div > div.title")).getText();

        //校验
        assert jump_title.equals(pre_title);

        //保存一份详情页url
        detailUrl = driver.getCurrentUrl();

    }
}
